package cn.gzsxt.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import cn.gzsxt.mapper.provider.PermissionProvider;

@Mapper
public interface PermissionMapper {
	
	/**
	 * 通过条件返回总记录数
	 * 
	 * @param condition
	 * @return
	 */
	@SelectProvider(type = PermissionProvider.class, method = "count")
	long count(Map<String, Object> condition);
	
	/**
	 * 通过编号删除记录
	 * @param permissionIds
	 * @return
	 */
	@DeleteProvider(type=PermissionProvider.class,method="deleteByIds")
	int deleteByIds(Object... permissionIds);

	/**
	 * 查询所有模块数据
	 * 
	 * @return
	 */
	@Select("SELECT * FROM tb_basic_permission")
	List<Map<String, Object>> findAll();

	/**
	 * 通过条件分页查询
	 * 
	 * @param condition
	 * @param start
	 *            = index * size （数据库索引从0开始）
	 * @param size
	 * @return
	 */
	@SelectProvider(type = PermissionProvider.class, method = "findByConditionAndPage")
	List<Map<String, Object>> findByConditionAndPage(@Param("condition") Map<String, Object> condition,
			@Param("start") int start, @Param("size") int size);
	
	/**
	 * 通过条件查询权限
	 * @param condition
	 * @return
	 */
	@SelectProvider(type = PermissionProvider.class, method = "findByCondition")
	List<Map<String, Object>> findByCondition(Map<String, Object> condition);
	
	/**
	 * 通过一个编号数组，返回查询的权限
	 * @param permissionIds
	 * @return
	 */
	@SelectProvider(type=PermissionProvider.class,method="findByIds")
	List<Map<String, Object>> findByIds(Object... permissionIds);

	/**
	 * 通过模块编号查询一条记录
	 * @param permissionId
	 * @return
	 */
	@Select("SELECT *	FROM tb_basic_permission WHERE PERMISSION_ID=#{permissionId}")
	Map<String,Object> findById(Object permissionId);
	
	/**
	 * 插入模块记录
	 * 
	 * @param permission
	 * @return
	 */
	@Insert("INSERT INTO tb_basic_permission	(PERMISSION_NAME, PERMISSION_ACTION, PERMISSION_TYPE, PERMISSION_KEY, MODULAR_ID, PERMISSION_IS_SHOW) VALUES (#{PERMISSION_NAME}, #{PERMISSION_ACTION}, #{PERMISSION_TYPE}, #{PERMISSION_KEY}, #{MODULAR_ID}, #{PERMISSION_IS_SHOW})")
	@Options(useGeneratedKeys = true, keyProperty = "PERMISSION_ID")
	int insert(Map<String, Object> permission);
	
	/**
	 * 更新模块非空的字段
	 * @param admin
	 * @return
	 */
	@UpdateProvider(type=PermissionProvider.class,method="updateForNotnull")
	int updateForNotnull(Map<String, Object> permission);


}
